package com.icangya.DAO.impl;

import com.icangya.DAO.IFbAddressDAO;
import com.icangya.domain.FbAddress;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public class FbAddressDAOImpl extends  BaseDAO<FbAddress> implements IFbAddressDAO {

    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public List<FbAddress> getFbAddressAll(String openId) {
        String hql="FROM FbAddress fd where fd.openId=?";
        List<FbAddress> list= (List<FbAddress>) getHibernateTemplate().find(hql,openId);
        if(list.size()>0)
             return list;
        return null;
    }

    @Override
    public FbAddress getAddressByOpenId(String openId, long id) {

        String hql="FROM FbAddress fd where fd.openId=? and fd.id=?";
        List<FbAddress> list= (List<FbAddress>) getHibernateTemplate().find(hql,openId,id);
        if(list.size()>0)
            return list.get(0);
        return null;
    }

    @Override
    public FbAddress getAddressDefault(String openId) {
        String hql="FROM FbAddress fd where fd.status=1 and fd.openId=?";
        List<FbAddress> list= (List<FbAddress>) getHibernateTemplate().find(hql,openId);
        if(list.size()>0)
            return list.get(0);
        return null;
    }
}
